import json
import logging

from crontab import CronTab
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.db import transaction

from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from rest_framework.authentication import TokenAuthentication
from rest_framework.parsers import JSONParser
from rest_framework.views import APIView

from backend.api import getResult
from backend.common.api_response import JsonResponse
from backend.common.common import record_dynamic
from backend.models import Sys_Environment, Project, Sys_Project, Sys_Model, Lyzd_Interface, Lyzd_Interface_Case, \
    Sys_Dic, \
    Lyzd_Interface_Header, Lyzd_Interface_Param, Lyzd_RunMsg, Lyzd_Interface_Case_Param, Lyzd_Interface_Action, \
    View_lyzd_run
from backend.notice.DingDing import DingDingNotice
from backend.serializers import Sys_ProjectSerializer, SysDicSerializer, Lyzd_Interface, \
    Sys_ModelSerializer, Sys_InterfaceSerializer, Sys_CaseSerializer, Lyzd_Interface_HeaderSerializer, \
    Lyzd_InterfaceParamSerializer, Lyzd_RunMsgSerializer, Lyzd_Interface_ActionSerializer, ViewInterfaceSerializer, \
    Sys_CaseParamSerializer
from backend.serializers import SysEnvironmentSerializer
from backend.api.getResult import *
import json
import numpy as np

logger = logging.getLogger(__name__)  # 这里使用 __name__ 动态搜索定义的 logger 配置，这里有一个层次关系的知识点。
"""
通用 用于前端下拉显示

"""


class project(APIView):

    # authentication_classes = (TokenAuthentication,)
    # permission_classes = ()

    def get(self, request):
        """
        获取用例分组
        :return:
        """

        # pro_data = Project.objects.get()
        pro_data = Sys_Project.objects.filter()  # filter()

        serialize = Sys_ProjectSerializer(pro_data, many=True)
        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


# getRunApiList


"""yunxin kaishi"""


# ProcesstTesting 流程测试
class ProcesstTesting(APIView):

    # authentication_classes = (TokenAuthentication,)
    # permission_classes = ()

    def get(self, request):
        """
        获取用例分组
        :return:
        """
        # 运行顺序 run_seq
        run_seq = request.GET.get("run_seq[]")  # 执行接口列表
        print(run_seq)
        print("AC")  #apicase
        run_ac = request.GET.get("run_ac[]")
        print(type(run_ac))

        print(run_ac)
        print(type(run_ac))
        print("AAAAAAAAAAAAAAAAA")
        run_ac = run_ac.strip(',')
        print(run_ac)

        run_ac_1 = run_ac.split(',')
        print(run_ac_1)

        run_ac_new = {}
        for i in run_ac_1:

            run_ac_2 = i.split(':')

            run_ac_new[run_ac_2[0]] = run_ac_2[1]
        print(run_ac_new)



        # run_ac_new = '{' + run_ac + '}'
        # run_ac_new = run_ac_new.replace(',}', "}")
        # run_ac_new = run_ac_new.replace(' ', "")
        # print(run_ac_new)
        # run_ac_new = eval(run_ac_new)
        # print(run_ac_new)
        # print(type(run_ac_new))
        # print(222222222222)
        """
        将组装说的dict存入txt
        等到读case时处理
        
        """
        # print(222222222222) {341: 114, 342: 120, 343: 119}

        # for i in range(len(run_ac)):
        #     # ['343--C1221', '341--广州政采代- C1703', '342--C1704', '']
        #     if run_ac[i] != '':
        #         print(run_ac[i])
        #         print(type(run_ac[i]))
        #         run_ac_new=run_ac_new+run_ac[i]
        #         # stri = run_ac[i]
        #         #
        #         # index = run_ac[i].index(':')
        #         # print(index)
        #         # print(stri)
        #         # print(stri[0:index])
        #         # print(11111111)
        #         # run_ac_new.append(str(run_ac[i][int(0): int(index)]))
        # print("run_ac_new")
        # print(run_ac_new)  # {300: 82, 359: 108, 303: 86, 341: 103, 346: 113, 347: 121}

        # 343--C1221!@#$%^&*341--广州政采代- C1703!@#$%^&*342--C1704!@#$%^&*
        # run_seq_list=''.join(run_seq)
        # print(run_seq_list)
        # print(type(run_seq_list))
        print("AAAAAAAAAAAAAAAAA")
        run_seq = run_seq.split('!@#$%^&*')
        print(type(run_seq))

        run_seq_new = []

        for i in range(len(run_seq)):
            # ['343--C1221', '341--广州政采代- C1703', '342--C1704', '']
            if run_seq[i] != '':
                print(run_seq[i])
                print(type(run_seq[i]))
                stri = run_seq[i]

                index = run_seq[i].index('--')
                print(index)
                print(stri)
                print(stri[0:index])
                print(11111111)
                run_seq_new.append(str(run_seq[i][int(0): int(index)]))
        print("run_seq_new")
        print(run_seq_new)  # ['343', '341', '342']
        """
        流程测试不能将mock和非mock分2种方式处理，必须严格按顺序执行
        
        """
        print("************")

        run_id = request.GET.get("run_ids[]")  # 执行接口列表
        print("原传值：%s" % run_id)

        run_ids = run_id.replace("[", '').replace("]", '').replace("/", '').replace('"', '')
        print("取出【】：%s" % run_ids)
        run_ids = run_ids.split(",")
        print("转列表：%s" % run_ids)  # ['341|0', '340|0']
        run_seq_new_mock = []  # 运行顺序带mock

        for i in range(len(run_seq_new)):
            print(i)
            for j in range(len(run_ids)):
                print(j)
                print(run_seq_new[i])
                print(run_ids[j])
                if run_seq_new[i] in run_ids[j]:  # 341 in 341|0
                    run_seq_new_mock.append(run_ids[j])
        print("BBBBB")
        print(run_seq_new_mock)
        print("此处是重点")

        run_seq_new_ids = []
        for i in run_seq_new_mock:
            print(i)
            print(i.split("|")[0])
            print(type(i.split("|")[0]))
            run_seq_new_ids.append(i.split("|")[0])
        print(run_seq_new_ids)
        print("马嘉璐新增！！！！！")

        project_id = request.GET.get("project_id")  # 项目
        environment_id = request.GET.get("environment_id")  # 环境id
        case_type_code_id = request.GET.get("case_type_code_id")  # 逻辑执行/常规执行

        # type 为0时为流程测试
        content = {
            "progect_id": project_id,
            "environment_id": environment_id,
            "run_seq_new_mock": run_seq_new_mock,
            "run_seq_new_ids": run_seq_new_ids,
            "execute": "1101",  # 流程测试特有字段
            'type': "0",
            'run_ac_new': run_ac_new  #{341: 114, 342: 111}

        }

        # "progect_id": project_id,
        # "environment_id": environment_id,
        # "interface_action": interface_action,
        # "interface_mock": interface_mock,
        # "execute": case_type_code_id,
        # 'type': "1"
        print("111111111")
        msg = getResult.get(request, content)
        print("2222222222233")

        """查询最新运行结果"""

        maxid_msg_data = Lyzd_RunMsg.objects.latest()

        maxid_msg_data.id

        msg_data = Lyzd_RunMsg.objects.filter(id=maxid_msg_data.id)

        serialize = Lyzd_RunMsgSerializer(msg_data, many=True)

        result_str = (serialize.data[0]['msg'])
        result_fg = '"共执行接口数量"'

        run_result = serialize.data[0]['msg']

        user_dict = json.loads(run_result)

        pici = "批次号" + str(user_dict['本批次'])

        # result=result_str.replace('{','')
        result2 = result_str[result_str.index(result_fg):]
        result3 = result2.replace('}', '')
        # result2 = result1.replace(',', '##')

        """调用钉钉通知"""

        DingDingNotice.DingdingNotice(pici, result3)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")
        # return JsonResponse(data=getResult.get(request,content),code="999999", msg=getResult.get(request,content))


class runApi(APIView):

    # authentication_classes = (TokenAuthentication,)
    # permission_classes = ()

    def get(self, request):
        """
        获取用例分组
        :return:
        """

        run_id = request.GET.get("run_ids[]")  # 执行接口列表
        print("原传值：%s" % run_id)

        run_ids = run_id.replace("[", '').replace("]", '').replace("/", '').replace('"', '')
        print("取出【】：%s" % run_ids)
        run_ids = run_ids.split(",")
        print("转列表：%s" % run_ids)  # ['341|0', '340|0']

        interface_action = []  # 正常接口|0
        interface_mock = []  # MOCK接口|1
        for i in run_ids:
            list1 = i.split("|")
            if list1[1] == "0":
                #     正常走执行
                interface_action.append(list1[0])
            elif list1[1] == "1":
                #     走mock
                interface_mock.append(list1[0])
            else:
                print("输入接口类型有误，暂只支持正常执行或mock")
        print(interface_action)
        print(interface_mock)

        project_id = request.GET.get("project_id")  # 项目
        environment_id = request.GET.get("environment_id")  # 环境id
        case_type_code_id = request.GET.get("case_type_code_id")  # 逻辑执行/常规执行

        # type 为1时为接口测试
        content = {
            "progect_id": project_id,
            "environment_id": environment_id,
            "interface_action": interface_action,
            "interface_mock": interface_mock,
            "execute": case_type_code_id,
            'type': "1"
        }
        msg = getResult.get(request, content)

        """查询最新运行结果"""

        maxid_msg_data = Lyzd_RunMsg.objects.latest()

        maxid_msg_data.id

        msg_data = Lyzd_RunMsg.objects.filter(id=maxid_msg_data.id)

        serialize = Lyzd_RunMsgSerializer(msg_data, many=True)

        result_str = (serialize.data[0]['msg'])
        result_fg = '"共执行接口数量"'

        run_result = serialize.data[0]['msg']

        user_dict = json.loads(run_result)

        pici = "批次号" + str(user_dict['本批次'])

        # result=result_str.replace('{','')
        result2 = result_str[result_str.index(result_fg):]
        result3 = result2.replace('}', '')
        # result2 = result1.replace(',', '##')

        """调用钉钉通知"""

        DingDingNotice.DingdingNotice(pici, result3)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")
        # return JsonResponse(data=getResult.get(request,content),code="999999", msg=getResult.get(request,content))


class environment(APIView):

    # authentication_classes = (TokenAuthentication,)
    # permission_classes = ()

    def get(self, request):
        """
        获取用例分组
        :return:
        """

        # pro_data = Project.objects.get()
        pro_data = Sys_Environment.objects.filter(delete_flag=0)  # filter()

        serialize = SysEnvironmentSerializer(pro_data, many=True)
        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


# runResult


class getRunResult(APIView):

    # authentication_classes = (TokenAuthentication,)
    # permission_classes = ()

    def get(self, request):
        """
        获取用例分组
        :return:
        """

        # pro_data = Project.objects.get()
        result_data = Lyzd_Interface_Action.objects.filter()  # filter()

        serialize = Lyzd_Interface_ActionSerializer(result_data, many=True)

        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


class model(APIView):

    # authentication_classes = (TokenAuthentication,)
    # permission_classes = ()

    def get(self, request):
        """
        获取用例分组
        :return:
        """

        # pro_data = Project.objects.get()
        pro_data = Sys_Model.objects.filter()  # filter()

        serialize = Sys_ModelSerializer(pro_data, many=True)
        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


class CaseType(APIView):

    def get(self, request):
        # pro_data = Project.objects.get()
        pro_data = Sys_Dic.objects.filter(type_key="case_type")  # filter()

        serialize = SysDicSerializer(pro_data, many=True)
        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


class Application(APIView):
    def get(self, request):
        # pro_data = Project.objects.get()
        pro_data = Sys_Dic.objects.filter(type_key="application")  # filter()

        serialize = SysDicSerializer(pro_data, many=True)
        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


class CheckType(APIView):

    def get(self, request):
        # pro_data = Project.objects.get()
        pro_data = Sys_Dic.objects.filter(type_key="check_type")  # filter()

        serialize = SysDicSerializer(pro_data, many=True)
        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


class APIList(APIView):

    # authentication_classes = (TokenAuthentication,)
    # permission_classes = ()

    def get(self, request):
        """
        获取用例分组
        :return:
        """

        # pro_data = Project.objects.get()
        pro_data = Lyzd_Interface_Case.objects.filter()  # filter()

        serialize = Sys_CaseSerializer(pro_data, many=True)
        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


# CaseGetHeader CaseGetParam
class CaseGetParam(APIView):

    # authentication_classes = (TokenAuthentication,)
    # permission_classes = ()

    def get(self, request):
        """
        获取用例分组
        :return:
        """
        intfaceID = request.GET.get("interfaceId")

        # pro_data = Project.objects.get() (type_key="case_type")
        pro_data = Lyzd_Interface.objects.filter(id=intfaceID)  # filter()

        serialize = Sys_InterfaceSerializer(pro_data, many=True)

        """获取关联表数据"""
        # 请求头表
        interface_header_data = Lyzd_Interface_Header.objects.filter(interface=intfaceID)

        data0 = Lyzd_Interface_HeaderSerializer(interface_header_data, many=True)
        # lyzd_interface_param
        interface_param = Lyzd_Interface_Param.objects.filter(interface=intfaceID)

        data1 = Lyzd_InterfaceParamSerializer(interface_param, many=True)

        jihe = []

        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=data1.data, code="999999", msg="成功！")


"""
getCasebyApiID
流程测试--根据id获取case，case非禁用即可
"""


class getCasebyApiID(APIView):
    authentication_classes = (TokenAuthentication,)
    permission_classes = ()

    def get(self, request):

        try:
            page_size = int(request.GET.get("page_size", 20))
            page = int(request.GET.get("page", 1))

        except (TypeError, ValueError):
            return JsonResponse(code="999985", msg="page and page_size must be integer!")
        print("LLLLLLLLLLLl")

        interfaceID = request.GET.get("interfaceId")
        print(interfaceID)

        project = Sys_Project.objects.filter(status=0)
        model = Sys_Model.objects.filter(status=0)
        print(project)
        print(model)
        # api = Lyzd_Interface.objects.filter(project__in=project, model__in=model)

        obi = Lyzd_Interface_Case.objects.filter(interface_id__id=interfaceID,
                                                 project__in=project,delete_flag=0).order_by(
            "delete_flag", "-id")
        print('!!!!!!!!!!!!!!!!!!!!!')
        print(obi)

        #
        # paginator = Paginator(obi, page_size)  # paginator对象
        # total = paginator.num_pages  # 总页数
        #
        # try:
        #
        #     obm = paginator.page(page)
        #
        # except PageNotAnInteger:
        #
        #     obm = paginator.page(1)
        # except EmptyPage:
        #
        #     obm = paginator.page(paginator.num_pages)
        serialize = Sys_CaseSerializer(obi, many=True)

        # json_data = serializers.serialize("json", obm, ensure_ascii=False)
        return JsonResponse(data={"data": serialize.data,
                                  # "page": page,
                                  # "total": total
                                  }, code="999999", msg="成功")


class CaseGetHeaderAndParam(APIView):
    """
    按照接口id反显数据
    此处获取数据
    """

    def get(self, request):
        """
        获取用例分组
        :return:
        """
        intfaceID = request.GET.get("interfaceId")
        pro_data = Lyzd_Interface.objects.filter(id=intfaceID)  # filter()
        serialize = Sys_InterfaceSerializer(pro_data, many=True)
        """获取关联表数据"""
        # 请求头表
        interface_header_data = Lyzd_Interface_Header.objects.filter(interface=intfaceID)
        data0 = Lyzd_Interface_HeaderSerializer(interface_header_data, many=True)
        # lyzd_interface_param
        interface_param = Lyzd_Interface_Param.objects.filter(interface=intfaceID)
        data1 = Lyzd_InterfaceParamSerializer(interface_param, many=True)

        return JsonResponse(data={'header': data0.data, 'params': data1.data}, code="999999", msg="成功！")


class CaseGetHeader(APIView):

    # authentication_classes = (TokenAuthentication,)
    # permission_classes = ()

    def get(self, request):
        """
        获取用例分组
        :return:
        """
        intfaceID = request.GET.get("interfaceId")

        # pro_data = Project.objects.get() (type_key="case_type")
        pro_data = Lyzd_Interface.objects.filter(id=intfaceID)  # filter()

        serialize = Sys_InterfaceSerializer(pro_data, many=True)

        """获取关联表数据"""
        # 请求头表
        interface_header_data = Lyzd_Interface_Header.objects.filter(interface=intfaceID)

        data0 = Lyzd_Interface_HeaderSerializer(interface_header_data, many=True)
        # lyzd_interface_param
        interface_param = Lyzd_Interface_Param.objects.filter(interface=intfaceID)

        data1 = Lyzd_InterfaceParamSerializer(interface_param, many=True)

        jihe = []

        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=data0.data, code="999999", msg="成功！")


class yilaiApi(APIView):

    # authentication_classes = (TokenAuthentication,)
    # permission_classes = ()

    def get(self, request):
        """
        获取用例分组
        :return:
        """

        """无条件查询查询接口"""

        """获取所有project，去掉status=1的project"""
        project = Sys_Project.objects.filter(status=0)
        """获取所有model，去掉status=1的model"""
        model = Sys_Model.objects.filter(status=0)

        pro_data = Lyzd_Interface.objects.filter(project__in=project, model__in=model)  # filter()

        serialize = Sys_InterfaceSerializer(pro_data, many=True)

        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


class getApiByProjectID(APIView):
    """带分页"""

    # authentication_classes = (TokenAuthentication,)
    # permission_classes = ()

    def get(self, request):
        """
        获取用例分组
        :return:
        """

        """根据项目名称查询接口并分页"""

        try:
            page_size = int(request.GET.get("page_size", 20))
            page = int(request.GET.get("page", 1))

        except (TypeError, ValueError):
            return JsonResponse(code="999985", msg="page and page_size must be integer!")

        project_id = request.GET.get("project_id")

        if project_id:
            # View_lyzd_run
            project = Sys_Project.objects.filter(status=0)
            model = Sys_Model.objects.filter(status=0)
            api = Lyzd_Interface.objects.filter(project__in=project, model__in=model)

            pro_data = View_lyzd_run.objects.filter(project_id=project_id, id__in=api).order_by("id")  # filter()


        else:
            return JsonResponse(code="999999", msg="失败")

        paginator = Paginator(pro_data, page_size)  # paginator对象
        total = paginator.num_pages  # 总页数

        try:

            obm = paginator.page(page)

        except PageNotAnInteger:

            obm = paginator.page(1)
        except EmptyPage:

            obm = paginator.page(paginator.num_pages)
        serialize = ViewInterfaceSerializer(obm, many=True)

        # json_data = serializers.serialize("json", obm, ensure_ascii=False)
        return JsonResponse(data={"data": serialize.data,
                                  "page": page,
                                  "total": total
                                  }, code="999999", msg="成功")

        # pro_data = Project.objects.get()
        pro_data = Lyzd_Interface.objects.filter(project=project_id)  # filter()

        serialize = Sys_InterfaceSerializer(pro_data, many=True)
        # obi = AutomationGroupLevelFirst.objects.filter(project=project_id)
        # serialize = AutomationGroupLevelFirstSerializer(obi, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


class CheckCondition(APIView):  # 获取校验条件

    def get(self, request):
        pro_data = Sys_Dic.objects.filter(type_key="check_condition")  # filter()

        serialize = SysDicSerializer(pro_data, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


class ActionCondition(APIView):  # 获取校验条件

    def get(self, request):
        pro_data = Sys_Dic.objects.filter(type_key="action_condition")  # filter()

        serialize = SysDicSerializer(pro_data, many=True)

        return JsonResponse(data=serialize.data, code="999999", msg="成功！")


class LyzdHome(APIView):
    def get(self, request):
        """
        获取用例分组
        :return:
        """

        """无条件查询查询接口"""

        """获取所有project，去掉status=1的project"""
        projectCount = Sys_Project.objects.filter(status=0)
        projectCountAll = Sys_Project.objects.filter()
        """获取所有model，去掉status=1的model"""
        modelCount = Sys_Model.objects.filter(status=0)
        modelCountAll = Sys_Model.objects.filter()

        interfaceCount = Lyzd_Interface.objects.filter(delete_flag=0)
        interfaceCountAll = Lyzd_Interface.objects.filter()

        caseCount = Lyzd_Interface_Case.objects.filter(delete_flag=0)
        caseCountAll = Lyzd_Interface_Case.objects.filter()
        envCount = Sys_Environment.objects.filter(delete_flag=0)
        envCountAll = Sys_Environment.objects.filter()
        runResultCount = Lyzd_Interface_Action.objects.filter()
        runResultCountSuccess = Lyzd_Interface_Action.objects.filter(interface_res='成功')
        project_per = (int(projectCount.__len__()) / int(projectCountAll.__len__())) * 100
        interface_per = (int(interfaceCount.__len__()) / int(interfaceCountAll.__len__())) * 100
        env_per = (int(envCount.__len__()) / int(envCountAll.__len__())) * 100
        model_per = (int(modelCount.__len__()) / int(modelCountAll.__len__())) * 100
        case_per = (int(caseCount.__len__()) / int(caseCountAll.__len__())) * 100
        result_per = (int(runResultCountSuccess.__len__()) / int(runResultCount.__len__())) * 100

        data = {
            'projectCount': projectCount.__len__(),
            'modelCount': modelCount.__len__(),
            'interfaceCount': interfaceCount.__len__(),
            'caseCount': caseCount.__len__(),
            'envCount': envCount.__len__(),
            'runResultCount': runResultCount.__len__(),

            'projectCountAll': projectCountAll.__len__(),
            'modelCountAll': modelCountAll.__len__(),
            'interfaceCountAll': interfaceCountAll.__len__(),
            'caseCountAll': caseCountAll.__len__(),
            'envCountAll': envCountAll.__len__(),
            'runResultCountSuccess': runResultCountSuccess.__len__(),

            'project_per': round(project_per, 2),
            'model_per': round(model_per, 2),
            'interface_per': round(interface_per, 2),
            'case_per': round(case_per, 2),
            'env_per': round(env_per, 2),
            'result_per': round(result_per, 2)
        }

        return JsonResponse(data=data, code="999999", msg="成功！")


# list 转成Json格式数据
def listToJson(lst):
    keys = [str(x) for x in np.arange(len(lst))]
    print(keys)
    list_json = dict(zip(keys, lst))
    print(list_json)
    str_json = json.dumps(list_json, indent=2, ensure_ascii=False)  # json转为string
    print(str_json)
    print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1")
    return str_json
